package com.situ.mall.entity;

// JSON格式的通用响应对象封装的就是后台返回给前台的所有信息
public class Result {
	private static final int ERROR = 1;
	private static final int SUCCESS = 0;
	private static final int NEED_LOGIN = 2;
	private static final int ILLEGAL_PERMISSION = 3;

	// 当前状态（程序员判断状态）:成功、失败、未登录、没有权限
	// 当前登录是成功还是失败要告诉前台，前台才能知道弹出的提示框用errorMsg、successMsg
	private Integer code;
	// 描述信息（主要是给用户看的提示信息）
	private String msg;
	// 总数量（按理说是不需要，主要是给LayUI table）
	private Integer count;
	// 后台返回给前端的数据 Object， User、List<User>
	private Object data;
	
//	private boolean success;
//	
//	public boolean isSuccess() {
//		return success;
//	}
//
//	public void setSuccess(boolean success) {
//		this.success = success;
//	}
	
	public boolean isSuccess() {
		return code == SUCCESS;
	}

	public Result() {
	}
	
	public Result(Integer code) {
		this.code = code;
	}

	public Result(Integer code, String msg) {
		this.code = code;
		this.msg = msg;
	}

	public Result(Integer code, String msg, Object data) {
		this.code = code;
		this.msg = msg;
		this.data = data;
	}
	
	public Result(Integer code, String msg, Object data, Integer count) {
		this.code = code;
		this.msg = msg;
		this.data = data;
		this.count = count;
	}
	


	// 告诉前台成功：code
	public static Result success() {
		return new Result(SUCCESS);
	}
	
	// 告诉前台成功：code、msg
	public static Result success(String msg) {
		return new Result(SUCCESS, msg);
	}
	
	// 告诉前台成功：code、msg、data
	public static Result success(String msg, Object data) {
		return new Result(SUCCESS, msg, data);
	}
	
	// 告诉前台成功：code、msg、data、count
	public static Result success(String msg, Object data, Integer count) {
		return new Result(SUCCESS, msg, data, count);
	}

	// 告诉前台成功：code
	public static Result error() {
		return new Result(ERROR);
	}
	
	// 告诉前台成功：code、msg
	public static Result error(String msg) {
		return new Result(ERROR, msg);
	}

	public Integer getCode() {
		return code;
	}

	public void setCode(Integer code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public Integer getCount() {
		return count;
	}

	public void setCount(Integer count) {
		this.count = count;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}
	
//	public String getCity() {
//		return "青岛";
//	}

}